#!/bin/bash
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage2}
SRC=${SRC:-/sources}

name=libstdc++-gcc-pass2
version=10.2.0

rm -fr $TMP
mkdir -p $TMP $LOG

tar xf $SRC/gcc-$version.tar.xz -C $TMP

{ time \
   {

    cd $TMP/gcc-$version

    ln -s gthr-posix.h libgcc/gthr-default.h

    mkdir -v build
    cd       build

    ../libstdc++-v3/configure            \
        CXXFLAGS="-g -O2 -D_GNU_SOURCE"  \
        --prefix=/usr                    \
        --disable-multilib               \
        --disable-nls                    \
        --host=$(uname -m)-lfs-linux-gnu \
        --disable-libstdcxx-pch

    make
    
    make install
    
    }
} 2>&1 | tee $name.log

[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
